package w5

import scala.collection.mutable._

class MyClass(val clsname: String) {
  private var map: Map[String, String] = Map()

  def join(name: String, zhiwei: String) {
    map.put(name, zhiwei)
  }

  def update(name: String, z: String): Unit = {
    println("调用了update方法")
    if (map.contains(name))
      map.put(name, z)
  }

  override def toString: String = clsname + "," + map
}

object MyClass {
  def main(args: Array[String]): Unit = {
    var b22 = MyClass("合大22级大众班")
    b22.join("朱蓉", "班长")
    b22.join("李孟萍", "学习委员")
    b22.join("薛刘恒", "团支部书记")
    b22.join("廖佳仪", "成员")
    println(b22)

    b22("廖佳仪") = "副班长"
    println(b22)
  }

  def apply(clsNAme: String): MyClass = {
    new MyClass(clsNAme)
  }
}
